﻿const mysql = require("mysql");
const config = require("../config/config");
const pool = mysql.createPool({
    host: "123.249.89.33",
    // host: "mysql.xuxiaowen.space",
    user: "xuxiaowen",
    password: "8750196",
    //  password: "",
    database: "baojia",
    port: 3306,
    multipleStatements: true,
});

const query = (sql, a, b, c, d) => {
    try {
        // console.log("sql", sql)
        return new Promise((resolve, reject) => {
            pool.query(sql, (err, data, fileds, a, b, c, d) => {
                if (err) {
                    // console.log("query数据库连接错误1");
                    // console.error('err:', err)
                    reject("query数据库连接错误12", fileds, err);
                } else {
                    // console.log("query数据库连接成功");
                    resolve(data, fileds, err, a, b, c, d);
                }
            })
            // .then((state) => {
            //     console.log(state)
            // })
            // .catch((error) => {
            //     console.log(error, 'Promise error');
            // });
        })
    } catch (error) {
        console.log("error", error);
        // console.error(error);
        // resolve(error);

    }

};

module.exports = query;